Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

418
Vistas
javacsript array map with double [[ ]] data

I have this array:

[ [ { "data1": 1, "data2": 2, }, { "data1": 1, "data2": 2, } ] ]

how can i remove the first parenthesis? i tried with reduce or map but return an error:

Cannot read properties of undefined (reading 'reduce') or Cannot read properties of undefined (reading 'map').

I have to retrieve some data inside it.

Thanks for your help.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

you can use array.flat() here

let x =[ [ { "data1": 1, "data2": 2, }, { "data1": 1, "data2": 2, } ] ]

let y = x.flat()

console.log(y) // [ { data1: 1, data2: 2 }, { data1: 1, data2: 2 } ]
about 4 years ago · Santiago Trujillo Denunciar

0

If your data is in an array arr, there are a couple of ways:

  1. Just do arr[0].map(...) (if your data looks like in your example)
  2. Use flatMap. If there is nesting like [ [ obj1, obj2 ], [ obj3, obj4 ] ] flatMap turns it to [obj1, obj2, obj3, obj4]

Example:

arr.flatMap(_ => _)

Edit: As others have mentioned, flat works just as well. It depends whether you want to perform some operations within the flatMap also, or to get an array of only the data1 properties of the objects in your example:

arr.flatMap(el => el["data1"]) 
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda